import Vue  from 'vue';
import Vuex from 'vuex';
Vue.use(Vuex)

export default new Vuex.Store({
    state: {
        LoginState:false,
        uN:'',
        deal:false,
        cards:[],
        Goods:[],
        clGoods:[],
        mycards:[],
        searchcards:[]

    },
    getters: {

    },
    mutations: {
        login (state) {
            state.LoginState=true
            state.uN =  window.localStorage.getItem("userName")
        },
        logout (state) {
            state.LoginState=false
            state.uN=""
        },
        Deal(state){
            state.deal=true
        },
        Nodeal(state){
            state.deal=false
        },
        gooddetail(state,n){         
            state.Goods.splice(0,state.Goods.length,state.cards[n])        
    },
    mygooddetail(state,n){         
        state.Goods.splice(0,state.Goods.length,state.mycards[n])        
},
searchdetail(state,n){         
    state.Goods.splice(0,state.Goods.length,state.searchcards[n])        
},
cleardetail(state){
    state.searchcards.splice(0,state.searchcards.length)
},

    clgoods(state,a){
            state.clGoods.push(state.Goods[a])
    }
    },
    actions: {
        login ({ commit }) {
            commit('login')
        },
        logout ({ commit }) {
            commit('logout')
        },
        Deal({commit}){
            commit('Deal')
        },
        Nodeal({commit}){
            commit('Nodeal')
        }
    }
})